package com.example.human_resource_management.mapper;

import com.example.human_resource_management.entry.dto.EmployeeForumAdminDto;
import com.example.human_resource_management.entry.po.EmployeeForum;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Lenovo
 * @description 针对表【employee_forum(员工论坛表)】的数据库操作Mapper
 * @createDate 2025-06-09 14:53:50
 * @Entity com.example.human_resource_management.entry.po.EmployeeForum
 */
public interface EmployeeForumMapper extends BaseMapper<EmployeeForum> {

    @Delete("""
        DELETE FROM employee_forum 
        WHERE emp_id = #{empId} AND post_id = #{postId}
    """)
    int deleteForumByEmpIdAndPostId(@Param("empId") Long empId, @Param("postId") Long postId);

    @Select("""
        SELECT 
            ef.post_id,
            e.name,
            e.gender,
            ef.title,
            ef.content,
            ef.post_time,
            ef.reply_count
        FROM 
            employee_forum ef
        INNER JOIN 
            employee e ON ef.emp_id = e.emp_id
    """)
    List<EmployeeForumAdminDto> selectAllEmployeeForums();
}